home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / addTwoCurves.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.0 KB  |  114 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //    Example script : Add two nurbs curves of the select list.
  19. //
  20. global proc int addTwoCurves() 
  21. {
  22.  
  23.     ///////////////////////////////////////////////////
  24.     // get the select list.
  25.     //
  26.     string $selList[] ;
  27.     int $len ;
  28.     $selList = `ls -sl` ;
  29.     $len = size($selList) ;
  30.     if( $len == 0 ) return 0 ;
  31.  
  32.     ///////////////////////////////////////////////////
  33.     // run filter to get the nurbsCurves alone.
  34.     //
  35.     string $crvList[] ;
  36.     global int $gSelectNurbsCurvesBit ;
  37.     $crvList = `filterExpand -ex true -sm $gSelectNurbsCurvesBit` ;
  38.     $len = size( $crvList ) ;
  39.     if( $len != 2 ) return 0 ;
  40.  
  41.     /////////////////////////////////////////////
  42.     // create average node.
  43.     //
  44.     int $ok = 1 ;
  45.     int $sc = 0  ;
  46.     string $avg ;
  47.     if( catch($avg = `createNode avgCurves`) ) {
  48.         $ok = 0 ;
  49.         $sc = 1 ;    
  50.     }
  51.  
  52.     /////////////////////////////////////////////
  53.     // connect input curves to average node.
  54.     //
  55.     if( $ok ) {
  56.         string $inAttr1 ;
  57.         string $inAttr2 ;
  58.  
  59.         string $shape1[] = `listRelatives -s $crvList[0]` ;
  60.         $inAttr1 = $shape1[0] + ".ws[0]" ;
  61.         string $shape2[] = `listRelatives -s $crvList[1]` ;
  62.         $inAttr2 = $shape2[0] + ".ws[0]" ;
  63.  
  64.         string $oAttr1 ;
  65.         string $oAttr2 ;
  66.         $oAttr1 = $avg + ".ic1" ;
  67.         $oAttr2 = $avg + ".ic2" ;
  68.  
  69.         if( catch( `connectAttr $inAttr1 $oAttr1` ) || catch( `connectAttr $inAttr2 $oAttr2` ) )  {
  70.             $ok = 0 ;
  71.         }
  72.         if( $ok == 1 ) { 
  73.             //$inAttr1 = $avg + ".rb" ;
  74.             //setAttr $inAttr1 0 ;
  75.  
  76.             // do not automate weights for averaging.
  77.             //
  78.             $inAttr1 = $avg + ".aw" ;
  79.             setAttr $inAttr1 0 ;
  80.         }
  81.     }
  82.  
  83.     /////////////////////////////////////////////////////
  84.     // curve shape to hold the weighted average result.
  85.     //
  86.     string $avgCurve ;
  87.     if( $ok ) {
  88.         if( catch( $avgCurve = `createNode nurbsCurve` ) ) {
  89.             $ok = 0 ;
  90.         } else {
  91.             $sc = 1 ;
  92.         } 
  93.     }
  94.  
  95.     /////////////////////////////////////////////////////
  96.     // connect average node output to curve shape.
  97.     // 
  98.     if( $ok ) {
  99.         string $inAttr ;
  100.         string $oAttr ;
  101.         //string $shape[] = `listRelatives -s $avgCurve` ;
  102.         $oAttr = $avgCurve + ".cr" ;
  103.         $inAttr = $avg + ".oc" ;
  104.         connectAttr $inAttr $oAttr ;
  105.     }
  106.  
  107.     if( $ok ) {
  108.         select -r $avgCurve ;
  109.     } else {
  110.         if( $sc == 1 ) delete $avg ;
  111.     }
  112.     return 1 ; 
  113. }
  114.